package futbol.tacticas.concursantes.The1A;

import java.awt.Point;

public class Utils {
	public static double Distance(Point a, Point b){
		return Math.sqrt(Math.pow(a.x-b.x,2)+Math.pow(a.y-b.y,2));
	}
	
	public static boolean isGoodGoal(Point a){
		return (a.x>=160 && a.y>-30 && a.y<30);
	}
	
	public static Point[] withReflections(Point[] players){
		Point[] res = new Point[players.length*3];
		for (int i = 0; i < players.length; i++)
		{
			res[3*i] = (Point)players[i].clone();
			res[3*i+1] = new Point();
			res[3*i+1].setLocation(players[i].getX(),240 - players[i].getY());
			res[3*i+2] = new Point();
			res[3*i+2].setLocation(players[i].getX(),-240 - players[i].getY());			
		}
		
		return res;
	}	
	
	public static boolean isNearestPlayerInAdvantage(int n, Point ball, Point[] players, Point[] enemies){
		Point me = players[n];
		
		double minDist = 1000;
		Point him = null;
		for (int i = 0; i < 11; i++){
			double dist = Distance(me, enemies[i]);
			if (dist < minDist){
				him = enemies[i];
			}
		}
		
		return Distance(me, ball) >= Distance(him, ball);
	}
	
	public static Point moveWithBall(Point from, Point to, int speed)
	{
		if (from == to)
			return from;
		
		Point dest = new Point();
		
		double ratio = Distance(from, to) / (5*speed);
		dest.setLocation(from.x + (to.x - from.x)/ratio, from.y + (to.y - from.y)/ratio);
		
		return dest;
	}
	
	public static int strenght;
}
